﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Messaging;
using System.Configuration;
using System.Text;

namespace Derrick.Web
{
    

    public partial class CallComet : System.Web.UI.Page
    {

        //private SIServer _cometServer = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            //_cometClientControl.MessageToSend = "<message>Testing...</message>";
            //_messageLabel.Text = _cometClientControl.MessageReceived;
            //AppConfig.BuildNewConfigFile(@"C:\Derrick\CometService\testcomet.conf");
            //AppConfig config = AppConfig.LoadConfig(@"C:\Derrick\CometService\testcomet.conf");
            //_cometServer = new SIServer(config.ServerInterface);
        }

        protected void _sendMsgButton_Click(object sender, EventArgs e)
        {
            try
            {
                //_cometServer.BroadcastMessage(_sendCometMsgTextBox.Text);
                string msgQueueName = ConfigurationManager.AppSettings["CometQueue"];
                MessageQueue intranetBannerQueue = new MessageQueue(msgQueueName);
                Message msg = new Message(_sendCometMsgTextBox.Text, new XmlMessageFormatter(new Type[] { typeof(string) }));
                intranetBannerQueue.Send(msg);
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
                Response.Write(error);
            }

        }

        protected void _numOfBytesSendButton_Click(object sender, EventArgs e)
        {
            string numOfBytesStr = _numberOfBytesTextBox.Text;

            if (String.IsNullOrEmpty(numOfBytesStr))
            {
                return;
            }

            int numOfBytes = Int32.Parse(numOfBytesStr);
            StringBuilder messageBuilder = new StringBuilder();

            for (int i = 0; i < numOfBytes; i++)
            {
                messageBuilder.Append("R");
            }

            try
            {
                //_cometServer.BroadcastMessage(_sendCometMsgTextBox.Text);
                string msgQueueName = ConfigurationManager.AppSettings["CometQueue"];
                MessageQueue intranetBannerQueue = new MessageQueue(msgQueueName);
                Message msg = new Message(messageBuilder.ToString(), new XmlMessageFormatter(new Type[] { typeof(string) }));
                intranetBannerQueue.Send(msg);
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
                Response.Write(error);
            }

        }
    }
}